<template>
  <div>
    <van-nav-bar title="商品列表">
      <template #left>
        <van-icon name="arrow-left" @click="goHome" />
      </template>
    </van-nav-bar>
    <van-card
      @click="onChange2(index)"
      v-for="(item, index) in goodsList"
      :key="index"
      :price="item.price"
      desc="描述信息xxx"
      :title="item.goodsname"
      :thumb="$host + item.img"
    >
      <template #footer>
        <van-button
          style="width: 40px"
          size="mini"
          icon="cart"
          type="primary"
        ></van-button>
      </template>
    </van-card>
    <van-empty description="没有商品" v-if="this.x" />
  </div>
</template>
<script>
export default {
  created() {
    this.$http
      .get("/getcategoods", { params: { sid: this.sid } })
      .then((res) => {
        this.goodsList = res.data.list.list;

        if (this.goodsList.length == 0) {
          this.x = true;
        } else {
          this.x = false;
        }
      });
  },

  methods: {
    goHome() {
      this.$router.go(-1);
    },
    onChange2(index){
      this.$router.push('goods/'+this.goodsList[index].id)
      console.log(this.goodsList[index].id)
    }
  },
  data() {
    return {
      sid: this.$route.params.id,
      goodsList: [],
      x: true,
    };
  },
};
</script>